package com.recharge.common.util;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ListUtil {

    /**
     * 计算切分次数
     */
    private static Integer countStep(Integer size, int input) {


        return (size + input - 1) / input;
    }

    /**
     * @param list  需要分隔的 集合
     * @param input 指定分隔size
     * @return
     */
    public static <T> List<List<T>> split(List<T> list, int input) {

        int limit = countStep(list.size(), input);
        List<List<T>> splitList;
        splitList = Stream.iterate(0, n -> n + 1).limit(limit).
                map(a -> list.stream().skip(a * input).limit(input).collect(Collectors.toList())).
                collect(Collectors.toList());
        //当输入数量小于分隔数量需反转
        if (input<limit){

            splitList = Stream.iterate(0, n -> n + 1).limit(input).
                    map(a -> list.stream().skip(a * limit).limit(limit).collect(Collectors.toList())).
                    collect(Collectors.toList());
        }


        return splitList;
    }

    public static void main(String[] args) {
        System.out.println(2001/500);
    }

}
